package algorithms;
import java.util.Map;
import java.util.Map.Entry;

import producer.bean.OrderInfo;
import producer.impl.Producer;
import algorithms.IAlgorithm;
/**
 * Algorytm wyszukukacy producentów po najlepszej cenie
 * @author Przemek Pioro
 *
 */
public class BestPrice implements IAlgorithm {
	private double price = 0.0;
	private Producer producer = null;

	@Override
	public Producer find(Map<Producer, OrderInfo> data) {
		price = 0.0;
		producer = null;
		for (Entry<Producer, OrderInfo> entry : data.entrySet()) {
			if(producer == null){
				price = entry.getValue().getCost();
				producer = entry.getKey();
			}else{
				if(entry.getValue().getCost() < price){
					price = entry.getValue().getCost();
					producer = entry.getKey();
				}	
			}
		}
		return producer;
	}

}
